﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using Core.Services.Menu;
using Core.Web.Pages.Menu.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace Core.Web.Pages
{
    public class IndexModel : PageModel
    {
        private readonly IMapper _mapper;
        private readonly IMenuService _menuService;
        public IndexModel(
            IMapper mapper,
            IMenuService menuService)
        {
            _mapper = mapper;
            _menuService = menuService;
        }

        public void OnGet()
        {
            //下一步，研究layX
        }

        public IActionResult OnPostMenus()
        {
            var menus = _mapper.Map<IEnumerable<MenuTreeViewModel>>(_menuService.GetList(c => !c.IsDel && c.IsActive, "parentId,seq"));
            return new JsonResult(menus);
        }
    }
}
